package model
{
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.events.IEventDispatcher;
	
	import mx.collections.ArrayCollection;
	import mx.collections.Sort;
	import mx.collections.SortField;
	
	import vo.User;
	import vo.Ware;
	[Bindable]
	public class ModelLocator extends EventDispatcher
	{
		
		private static var _instance:ModelLocator;
		public static function GetInstance():ModelLocator
		{
			if( _instance == null )
			{
				_instance = new ModelLocator();
			}
			return _instance;
		}
		public function ModelLocator(target:IEventDispatcher=null)
		{
			//article = new Article();
			ware = new Ware();
			curUser = new User();
			wareList = new ArrayCollection();
			typeList = new ArrayCollection();
			typeCombo = new Array();
			curWareList = new ArrayCollection();
			shoreList = new ArrayCollection(
				[{label:"选择分店", data:null},
				{label:"万众城", data:"REMAINWZ"},
				{label:"美丽365", data:"REMAINML"},
				{label:"观澜", data:"REMAINGL"}]);
			ticketWareList = new ArrayCollection();
			ticketList = new ArrayCollection();
			ticketDetails = new ArrayCollection();
			userList = new ArrayCollection();
			traceList = new ArrayCollection();
			ticketDailyValue = new ArrayCollection();
			clientList = new ArrayCollection();
		}
		public var isLogin:Boolean = false;
		public var ware:Ware;
		public var editWare:Ware;
		public var curWareList:ArrayCollection;
		public var curUser:User;
		public var userList:ArrayCollection;
		public var wareList:ArrayCollection;
		public var typeList:ArrayCollection;
		public var typeCombo:Array;
		public var shoreList:ArrayCollection;
		public var ticketWareList:ArrayCollection;
		public var ticketList:ArrayCollection;
		public var testBind:ArrayCollection;
		public var ticketDetails:ArrayCollection;
		public var traceList:ArrayCollection;
		public var ticketValue:Number;
		public var ticketDailyValue:ArrayCollection;
		public var clientList:ArrayCollection;
		public function UpdateTicketStat(evt:Event):void
		{
			ticketValue = 0;
			var dailyArr:Array = new Array();
			ticketDailyValue.removeAll();
			for( var i:int = ticketList.length-1; i >=0; i -- )
			{
				ticketValue += Number( ticketList[i].realPay );
				if( dailyArr[ticketList[i].ticketDate] != null )
				{
					dailyArr[ticketList[i].ticketDate] += Number( ticketList[i].realPay );
				}
				else
				{
					dailyArr[ticketList[i].ticketDate] = Number( ticketList[i].realPay );
				}
			}
			for( var keyName:String in dailyArr )
			{
				var tmpObj:Object = new Object();
				tmpObj.date = keyName;
				tmpObj.value = dailyArr[keyName];
				ticketDailyValue.addItem(tmpObj);
			}
			// 进行日期排序
			var sort:Sort = new Sort();
			sort.fields = [new SortField("date" )];
			ticketDailyValue.sort = sort;
			this.ticketDailyValue.refresh();
		}
		
	}
}
